#include "stdafx.h"

/********************************
* Add a WndPointer to Table
***/
void WndPointerTable::Add(WndPointerItem& WndPointer)
{
	WndPointerItem* pAdd = new WndPointerItem(WndPointer.pWnd, WndPointer.hWnd);
	if (pStart == 0)
	{
		pStart = pAdd;
		return;
	}
	WndPointerItem* pTemp = pStart;
	while(pTemp->pNext != 0)
	{
		pTemp = pTemp->pNext;
	}
	pTemp->pNext = pAdd;
};

/********************************
* Clear the table and release resources
***/
void WndPointerTable::Clear()
{
	if (pStart == 0)
		return;
	WndPointerItem* pTemp = pStart;
	while (pStart !=0)
	{
		pTemp = pStart;
		pStart = pStart->pNext;
		delete pTemp;
	}
	pStart = 0;
	pTemp = 0;
}

/*******************************
 * Find the pWnd according to HWND
 ***/
Wnd* WndPointerTable::Find(HWND hwnd)
{
	WndPointerItem* pTemp = pStart;
	while (pTemp !=0)
	{
		if(pTemp->hWnd == hwnd)
			return pTemp->pWnd;
		pTemp = pTemp->pNext;
	}
	return 0;
}